package core.weapons;
import java.awt.*;

import core.Player;
import core.units.Unit;


/**
 * 
 * @author Anton
 * OUTDATED
 */
public class Claymore extends Attack{
	
	int checkRadius = 70, delayTime = 10;
	int explodeTime = 200, explodeRadius = 75;
	int timeElapsed = 0, explodeFrame = 0;
	boolean exploding = false;
	double dx, dy, distance;
	int calmRadius = 16;
	int time = 0;
	
	Claymore(int inX, int inY, Player m) {
		super(inX, inY, m);
		lifetime = 200;
		damage = 5;
	}
	
	public void checkHit(Unit u) {
		if(u.getTeam()!=team) {
			dx = (x-u.getX());
			dy = (y-u.getY());
			distance = Math.sqrt(dx*dx+dy*dy);
			if(distance<checkRadius) {
				if(exploding) {
					u.takeDamage(damage);
				}
				else {
					exploding = true;
				}
			}		
		}
		
	}
	
	public void nextFrame() {
		if(exploding) {
			explodeFrame++;
			lifetime--;
		}
		if(lifetime==0) {
			main.attacks.remove(this);
		}
		if(time == 20) {
			time = 0;
		}
		else {
			time++;
		}
	}
	
	public void paint(Graphics g) {
		if(exploding) {
			g.setColor(Color.red);
			int tempPaintSize= (int)(explodeRadius-(explodeRadius*(explodeFrame/(lifetime+1))))*2;
			//g.fillOval(x-calmRadius,y-calmRadius,calmRadius*2,calmRadius*2);
			g.fillOval((x-explodeRadius), (y-explodeRadius), tempPaintSize, tempPaintSize);
		}
		else {
			g.setColor(Color.darkGray);
			g.fillOval(x-calmRadius,y-calmRadius,calmRadius*2,calmRadius*2);
			if(time>=10) {
				g.setColor(Color.red);
				g.fillOval(x-calmRadius/4, y-calmRadius/4, calmRadius/2, calmRadius/2);
			}
		}
		
	}
}
